package net.googlecode.kharchenko.services.impl;

import net.googlecode.kharchenko.services.SecurityService;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.stereotype.Service;


/**
 * Implementation of SecurityService to get access to current user.
 */
@Service
public class SecurityServiceImpl implements SecurityService {


    public String getCurrentUser() {

        Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        if (principal instanceof UserDetails) {

            return ((UserDetails) principal).getUsername();
        } else {
            return principal.toString();
        }


    }

    ;
}
